# -*- coding:utf-8 -*-
from datetime import datetime, timedelta

from infrastructure.utils.enums import DateFormat


def getTodayyyyymmddInt() -> int:
    today = datetime.today()
    return int(today.strftime("%Y%m%d"))


def getNowDateStr(dateFormat: DateFormat=DateFormat.Y_m_d) -> str:
    now = datetime.now()
    return now.strftime(dateFormat.value)


def generatePastDateString(n: int) -> str:
    if n < 0:
        raise ValueError("The number of days must be a non-negative integer.")
    today = datetime.today()
    try:
        past_date = today - timedelta(days=n)
    except OverflowError:
        raise ValueError("The specified number of days is out of the supported date range.")
    return past_date.strftime("%Y%m%d")


def differenceFromNow_Days(dti: int) -> int:
    dt = datetime.strptime(str(dti), DateFormat.Ymd.value)
    dt2 = datetime.now()
    return (dt2 - dt).days + 1


if __name__ == '__main__':
    print(generatePastDateString(4))